<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            padding: 0;
            margin: 0;
            box-sizing: border-box;
        }
        .box{
            width: 100px;
            height: 100px;
            background-color: aqua;
        }
        .del{
            width: 80%;
            margin: 20px auto;
            height: 100px;
            background-color: red;
            text-align: center;
            line-height: 100px;
            display: flex;
            flex-wrap: wrap;
            justify-content: space-around;
        }
        ul li{
            height: 50px;
            line-height: 50px;
            border-bottom: 1px solid #ccc;
        }
        .bg{
            background-color: red;
        }
    </style>
</head>
<body>
    <div draggable="true" class="box">box</div>
    <ul>
        <li>1</li>
        <li>2</li>
        <li>3</li>
        <li>4</li>
        <li>5</li>
        <li>6</li>
        <li>7</li>
        <li>8</li>
        <li>9</li>
        <li>10</li>
    </ul>
    <div class="del">删除区</div>
    <script >
        const box = document.querySelector('.box')
        const del = document.querySelector('.del')
        const list = [...document.querySelectorAll('ul li')]
        // 源对象开始拖拽
        box.addEventListener('dragstart',()=>{
            console.log('开始拖拽')
        })
        // 源对象正在拖拽
        box.addEventListener('drag',()=>{
            console.log('正在拖拽')
        })
         // 源对象结束拖拽
        box.addEventListener('dragend',()=>{
            console.log('结束拖拽')
        })
        list.forEach(li =>{
            li.addEventListener('dragenter',e =>{
                li.classList.add('bg')
            })
            li.addEventListener('dragleave',e =>{
                li.classList.remove('bg')
            })
        })
        // 阻止目标对象的默认dragover事件
        // e.prevenrDefault阻止默认事件发生 
        del.addEventListener('dragover',e=>{e.preventDefault()})
        del.addEventListener('drop',e=>{
            const newBox = box.cloneNode(true)
            del.appendChild(newBox)
            box.remove()
        })

    </script>
</body>
</html>